﻿// This Code is written by Tahir Çakmak, tahircakmak.blogspot.com
using System;
using System.ServiceModel;
using ServiceLibrary;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ServiceLibrary;
using System.ServiceModel;
using System.Configuration;

namespace MainLibrary
{
public static class Core
{
    public static IComplexService ComplexService
    {
        get
        {
            if (ConfigurationManager.AppSettings["userService"] == "1")
                return new ComplexService();
            //return new ChannelFactory<IComplexService>("BasicHttpBinding_ComplexService").CreateChannel();

            var proxyCreater = new ProxyFactory<IComplexService>(
                            new ChannelFactory<IComplexService>("BasicHttpBinding_ComplexService")
                                .CreateChannel()
                            );

            return proxyCreater.GetProxy(fnc =>
                {
                    using (OperationContextScope scope = new OperationContextScope(proxyCreater.RealObject as IContextChannel))
                    {
                        return fnc.Invoke();
                    }
                });
        }
    }
}
   
}
